package Demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-06
 * Time: 11:38
 */

class Student implements Comparable<Student> {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    //根据年龄比较
//    @Override
//    public int compareTo(Student o) {
////        if (this.age > o.age) {
////            return 1;
////        } else if (this.age == o.age) {
////            return -1;
////        } else {
////            return 0;
////        }
////    }
//        return this.age - o.age;
//    }
    @Override
    public int compareTo(Student o) {
        return (this.name.compareTo(o.name));
    }


}

public class Test {
    public static void main1(String[] args) {
        String str1 = "abcd";
        String str2 = "cdef";
        System.out.println(str1.compareTo(str2));
    }

    public static void main(String[] args) {

        Student student1 = new Student("ZhangSan", 10);
        Student student2 = new Student("LiSi", 9);
//        int ret = student1.compareTo(student2);
        if (student1.compareTo(student2) > 0) {
            System.out.println("student1>student2");
        } else {
            System.out.println("student1<=student2");
        }
    }
}